package com.momin.gmall.product.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.momin.common.utils.PageUtils;
import com.momin.common.utils.Query;

import com.momin.gmall.product.dao.CategoryBrandRelationDao;
import com.momin.gmall.product.entity.CategoryBrandRelationEntity;
import com.momin.gmall.product.service.CategoryBrandRelationService;


@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CategoryBrandRelationEntity> page = this.page(
                new Query<CategoryBrandRelationEntity>().getPage(params),
                new QueryWrapper<CategoryBrandRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryBrandCategoryPage(Map<String, Object> params, Long brandId) {
        Query<CategoryBrandRelationEntity> categoryBrandRelationEntityQuery = new Query<>();
        QueryWrapper<CategoryBrandRelationEntity> categoryBrandRelationEntityQueryWrapper = new QueryWrapper<>();
        categoryBrandRelationEntityQueryWrapper.eq("brand_id",brandId);
        IPage<CategoryBrandRelationEntity> page = this.page(categoryBrandRelationEntityQuery.getPage(params),categoryBrandRelationEntityQueryWrapper);
        return new PageUtils(page);
    }

    @Override
    public List<CategoryBrandRelationEntity> queryBrandCategoryByBandIdAndCatId(Long brandId, Long catId) {
        QueryWrapper<CategoryBrandRelationEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("brand_id",brandId).and((wrapper)->{
            wrapper.eq("catelog_id",catId);
        });
        List<CategoryBrandRelationEntity> entities = this.baseMapper.selectList(queryWrapper);
        return entities;
    }

}